/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024.
 * Description: support software random number interrupt entropy source
 * Author: zhuyan
 * Create: 2024-01-27
 */
#include <linux/notifier.h>
#include <linux/jump_label.h>

static ATOMIC_NOTIFIER_HEAD(rtos_swrng_irq_chain);

DEFINE_STATIC_KEY_FALSE(swrng_enabled);

int rtos_swrng_irq_register(struct notifier_block *nb)
{
	return atomic_notifier_chain_register(&rtos_swrng_irq_chain, nb);
}
EXPORT_SYMBOL_NS(rtos_swrng_irq_register, HW_RTOS_NS);

int rtos_swrng_irq_unregister(struct notifier_block *nb)
{
	return atomic_notifier_chain_unregister(&rtos_swrng_irq_chain, nb);
}
EXPORT_SYMBOL_NS(rtos_swrng_irq_unregister, HW_RTOS_NS);

void swrng_irq_call_chain(void)
{
	if (static_branch_unlikely(&swrng_enabled))
		atomic_notifier_call_chain(&rtos_swrng_irq_chain, 0, NULL);
}

void rtos_swrng_enable(void)
{
	static_branch_enable(&swrng_enabled);
	pr_info("rtos software random number generator enabled\n");
}
EXPORT_SYMBOL_NS(rtos_swrng_enable, HW_RTOS_NS);

void rtos_swrng_disable(void)
{
	static_branch_disable(&swrng_enabled);
	pr_info("rtos software random number generator disabled\n");
}
EXPORT_SYMBOL_NS(rtos_swrng_disable, HW_RTOS_NS);
